﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Private.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Global" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <script type="text/javascript">
        function hasClass(el, name) {
            return new RegExp('(\\s|^)' + name + '(\\s|$)').test(el.className);
        }
        function addClass(el, name) {
            if (!hasClass(el, name)) { el.className += (el.className ? ' ' : '') + name; }
        }
        function removeClass(el, name) {
            if (hasClass(el, name)) {
                el.className = el.className.replace(new RegExp('(\\s|^)' + name + '(\\s|$)'), ' ').replace(/^\s+|\s+$/g, '');
            }
        }
        function RegisterReplyButtonMem(comid) {
            var formReply = document.getElementById("formReply_" + comid);
            removeClass(formReply, "hidden");
        }
        function RegisterReplyButtonMemNews(comid) {
            var formReply = document.getElementById("formReplyNews_" + comid);
            removeClass(formReply, "hidden");
        }
    </script>
    <script type="text/javascript">
        function LikeCLick(obj) {
            var sid = $('#LikeButton').data("url");
            var sid = obj;
            $.ajax({
                type: "POST",
                url: "/News/Like",
                data: "proId=" + sid,
                success: function (result) {

                    if (result == "null") {
                        alert("Đăng nhập để thích");
                    }
                    else {
                        if (result == "duplicated")
                            alert("Bạn đã thích rồi");
                        else {
                            var ff = document.getElementById("LikeField_" + sid);
                            ff.innerHTML = "Thích: Có " + result + " người thích";

                        }
                    }
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }
    </script>
    <%
        var hMem = (MemberHelper)ViewData["hMem"];
    %>
    <div class="private_share_post_top">
        <div class="private_sharepost_menu">
            <ul>
                <li><a href="canhan_sp_detail_private.html" class="menu_select">Chia sẻ</a></li>
                <li><a href="#">Bài viết yêu thích</a></li>
            </ul>
        </div>
        <% 
            if (Session["MemId"] != null)
            {
                //Check if this member is owner of this page or not
                if (hMem.Member.MemId == (int)Session["MemId"])
                {
        %>
        <div class="private_write_right">
            <div class="private_bt_newspost">
                <a href="<%= Url.Action("Create","News", new {uid=Session["MemId"]} ) %>">
                    <img src="/../Content/Images/icon_newpost.gif">
                    Viết bài mới... </a>
            </div>
        </div>
        <%}
            }%>
    </div>
    <%
        var isOwner = (bool)ViewData["IsOwner"];
        //var lstNewNews = (List<News>)hMem.getNewNews(1, Config.ITEMS_PER_PAGE);
        NewsHelper.FetchNewsResult lstNewNews = (NewsHelper.FetchNewsResult)ViewData["ListNews"];
        if (lstNewNews.news != null && lstNewNews.news.Count > 0)
        {
            foreach (var n in lstNewNews.news)
            {
    %>
    <!-- Thum ad hot -->
    <div class="private_thumb_listpr">
        <div class="private_img_post_bt">
            <%--<a href="<%=Url.Action("Detail", "News", new { uid = hMem.Member.MemId, newsId= n.NewsId, title = WebHoiChoMuaBan.Controllers.Utility.MiscUtil.EscapeString(n.NewsTitle),isEditMode = "False" })%>">--%>
             <a href="/News/Detail?uid=<%=hMem.Member.MemId %>?newsId=<%=n.NewsId %>">
                <img src="/../Content/Images/Upload/Thumbnail/<%=n.NewsThumb %>" class="private_img_post"
                    width="140" height="101" alt="<%=n.NewsTitle %>" />
            </a>
        </div>
        <div class="private_post_text">
            <p class="private_text_title">
                <%--<a href="<%=Url.Action("Detail", "News", new { uid = hMem.Member.MemId, newsId= n.NewsId, title = WebHoiChoMuaBan.Controllers.Utility.MiscUtil.EscapeString(n.NewsTitle),isEditMode = "False" })%>">
                    <%=n.NewsTitle %></a>--%>
                     <a href="/News/Detail?uid=<%=hMem.Member.MemId %>&newsId=<%=n.NewsId %>"> <%=n.NewsTitle %></a>
                <p>
                    <%=n.NewsIntro %>
                    <br />
                    <div id="LikeField_<%= n.NewsId%>">
                        Thích: Có <%=n.NewsLike %> người thích
                    </div>
                    <br />
                </p>
                <br />
                <div class="private_listpr_active">
                    <div class="private_content_rp">
                        <span>
                            <img src="/../Content/Images/turnview.gif">&nbsp;&nbsp;Lượt xem:
                            <%=n.NewsViewCount %></span>
                    </div>
                    <% if (Session["MemId"] != null && int.Parse(Session["MemId"] + "") == n.Member.MemId)
                       {
                    %>
                    <div class="private_content_rp">
                        <span><a href='#noibat' class='hoicho_bt_action' onclick="LikeCLick(<%=n.NewsId%>)"
                            id='LikeButton' data-url="<%=n.NewsId %>">Thích</a></span>
                    </div>
                    <div class="private_content_rp" onclick="RegisterReplyButtonMemNews(<%=n.NewsId %>)">
                        <span>
                            <img src="/../Content/Images/comments_bt.gif">&nbsp;&nbsp;Bình luận</span>
                    </div>
                    <%
                        }
                       else
                       {
                           Response.Write("Đăng nhập để like và bình luận");
                       }
                    %>
                    <form action="<%=Url.Action("AddComment", "News") %>" id="formReplyNews_<%=n.NewsId %>"
                    method="post" class="hidden private_content_comment">
                    <input type="hidden" value="<%=n.NewsId %>" name="newsId" id="newsId" />
                    <div class="private_menu_topmenu">
                        <textarea class="input_full" rows="5" cols="45" id="txtComment" name="txtComment"></textarea>
                    </div>
                    <div class="private_post_text">
                        <div class="private_button_left">
                            <span class="private_font_bold">Chọn icon: </span>
                            <% ChatHelper chat = new ChatHelper();
                               List<ChatEmotionDetail> icons = chat.getEmotionPath();
                               foreach (ChatEmotionDetail icon in icons)
                               {
                                   Response.Write("<img align='middle' onclick='MemchatIconClick(this)' src='" + icon.path + "' id='" + icon.notation + "' width='40px' height='40px' />");

                               }
                            %>
                            <script type="text/javascript">
                                function MemchatIconClick(obj) {
                                    $this = document.getElementById("txtComment");
                                    $this.value += obj.id;
                                }
                            </script>
                        </div>
                        <div class="private_write_right">
                            <input type="submit" style="#width: 60px;" id="" value="Gửi" class="private_bt_submit_news_disable" />
                        </div>
                    </div>
                    </form>
                    <% if (isOwner)
                       {
                    %>
                    <div class="private_content_rp">
                        <a href="#">
                            <img src="/../Content/Images/delete_bt.gif" alt=""></a>
                    </div>
                    <%
                        }
                    %>
                </div>
        </div>
    </div>
    <!-- End Thum ad hot -->
    <%
}
        }
    %>
    <!-- Thum ad hot -->
    <!-- End Thum ad hot -->
    <center>
        <div class="private_breakpage">
            <%
                        
                int p;
                if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
                //if(p!=0)
                {
                    p = 1;
                }
                else p = int.Parse(Request.QueryString["p"]);
            %>
            <% if (p > 1)
               { %><a href='<%=string.Format("{0}?p={1}'",
                                                          Url.RouteUrl("PrivateLatestNewsRoute", new { uid =hMem.Member.MemId}),
                                                            p-1) %>'><img src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
                   trước</a>
            <% } %>
            <%
                if (p > 3)
                    Response.Write(string.Format("<a href='{0}?p={1}'{2}>{3}</a> ",
                                                  Url.RouteUrl("PrivateLatestNewsRoute", new { uid = hMem.Member.MemId }),
                                                    1,
                                                    string.Empty,
                                                     1));
                if (p > 4)
                    Response.Write("...");
                int total = lstNewNews.totalPages;
                int from = (p - 2 < 1 ? 1 : p - 2);
                int to = (p + 2 >= total ? total : p + 2);
                for (int i = from; i <= to; i++)
                    Response.Write(string.Format("<a href='{0}?p={1}'{2}>{3}</a> ",
                                                    Url.RouteUrl("PrivateLatestNewsRoute", new { uid = hMem.Member.MemId }),
                                                    i,
                                                    (i == p ? "class='menu_select'" : string.Empty),
                                                     i));
                if (p <= total - 4)
                    Response.Write("...");
                if (p <= total - 3)
                    Response.Write(string.Format("<a href='{0}?p={1}'{2}>{3}</a> ",
                                                  Url.RouteUrl("PrivateLatestNewsRoute", new { uid = hMem.Member.MemId }),
                                                    total,
                                                    string.Empty,
                                                    total));
            %>
            <% if (p < lstNewNews.totalPages)
               { %><a href='<%=string.Format("{0}?p={1}'",
                                                              Url.RouteUrl("PrivateLatestNewsRoute", new { uid = hMem.Member.MemId }),
                                                            p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a>
            <% } %>
        </div>
    </center>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
    Danh sách bài viết
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
</asp:Content>
